package com.uft.security.tam.utils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class FakeHeadersRequest extends HttpServletRequestWrapper{
	private static String loggedInUserName="admin";
	private static String httpRequestHeaderName="iv-user";
	private static String httpRequestHeaderGroupName="iv-groups";
	public FakeHeadersRequest(HttpServletRequest request) {
		super(request);
		// TODO Auto-generated constructor stub
	}
	
	public String getHeader(String name){
		HttpServletRequest request=(HttpServletRequest)getRequest();
		if(FakeHeadersRequest.httpRequestHeaderName.equals(name)){
			return loggedInUserName;
		}
		if(FakeHeadersRequest.httpRequestHeaderGroupName.equals(name)){
			return "restart_TEST,restart_server1, WebSphereConsoleUsers";
		}
		return request.getHeader(name);
	}
	
	public Enumeration getHeaderNames(){
		List list= new ArrayList();
		HttpServletRequest request = (HttpServletRequest)getRequest();
		Enumeration e = request.getHeaderNames();
		while(e.hasMoreElements()){
			String n= (String)e.nextElement();
			list.add(n);
		}
		list.add(FakeHeadersRequest.httpRequestHeaderName);
		list.add(FakeHeadersRequest.httpRequestHeaderGroupName);
		Enumeration en= Collections.enumeration(list);
		return en;
	}

}
